package com.xinyun.server.protocol.receive;

import com.xinyun.server.protocol.ProtocolData;
import com.xinyun.server.protocol.ProtocolDataHeader;
import com.xinyun.server.util.Utils;
import io.netty.buffer.ByteBuf;

/**
 * Created by bubusy on 16/5/22.
 */
public class InverterWarnData extends ProtocolData {


    public int pid;
    public int mid;

    public float dcu1;
    public float dci1;
    public float dcu2;
    public float dci2;
    public float dcu3;
    public float dci3;
    public float dcu4;
    public float dci4;

    public float acua;
    public float acia;
    public float acub;
    public float acib;
    public float acuc;
    public float acic;

    public float ivtemp;
    public float tolgencap;
    public int ivstatus;
    public int iverror;
    public int ivmode;
    public float fr;
    public int ivrun;
    public int monthgencap;
    public int lastmonthgencap;
    public float daygencap;
    public float lastdaygencap;
    public float powerlimitpercent;
    public int activepower;
    public int reactivepower;
    public int apparentpower;
    public float powerfactor;
    public int ivtype;

    public int boardtemp1;
    public int boardtemp2;
    public int currentleak;
    public int boardsumgen;
    public int boardsumuse;

    public String time;

    public InverterWarnData(ProtocolDataHeader header, ByteBuf bodyBytes) {

        super(header, bodyBytes);
    }

    public static InverterWarnData parseFromProtocolData(ProtocolData protocolData) {
        InverterWarnData obj = new InverterWarnData(protocolData.getHeader(), protocolData.getBodyBytes());
        ByteBuf body = protocolData.getBodyBytes().copy();

        obj.pid = body.readShortLE();
        obj.mid = body.readShortLE();

        obj.dcu1 = body.readShortLE();
        obj.dci1 = body.readShortLE();
        obj.acuc = body.readShortLE();
        obj.acic = body.readShortLE();
        obj.ivtemp = body.readShortLE();
        obj.tolgencap = body.readIntLE();
        obj.ivstatus = body.readShortLE();
        obj.iverror = body.readShortLE();
        obj.ivmode = body.readByte();
        obj.fr = body.readShortLE();
        obj.dcu2 = body.readShortLE();
        obj.dci2 = body.readShortLE();
        obj.ivrun = body.readByte();
        obj.monthgencap = body.readShortLE();
        obj.lastmonthgencap = body.readShortLE();
        obj.daygencap = body.readShortLE();
        obj.lastdaygencap = body.readShortLE();
        obj.dcu3 = body.readShortLE();
        obj.dci3 = body.readShortLE();
        obj.dcu4 = body.readShortLE();
        obj.dci4 = body.readShortLE();
        obj.powerlimitpercent = body.readShortLE();
        obj.activepower = body.readIntLE();
        obj.reactivepower = body.readIntLE();
        obj.apparentpower = body.readIntLE();
        obj.powerfactor = body.readShortLE();
        obj.acua = body.readShortLE();
        obj.acia = body.readShortLE();
        obj.acub = body.readShortLE();
        obj.acib = body.readShortLE();
        obj.ivtype = body.readShortLE();

        obj.boardtemp1 = body.readShortLE();
        obj.boardtemp2 = body.readShortLE();
        obj.currentleak = body.readByte();
        obj.boardsumgen = body.readIntLE();
        obj.boardsumuse = body.readIntLE();
        obj.time = Utils.parseTime(body);


        return obj;
    }

    @Override
    public String toString() {
        String str = "pid:" + this.pid + " "
                + "mid:" + this.mid + " "
                + "dcu1:" + this.dcu1 + " "
                + "dci1:" + this.dci1 + " "
                + "acuc:" + this.acuc + " "
                + "acic:" + this.acic + " "
                + "ivtemp:" + this.ivtemp + " "
                + "tolgencap:" + this.tolgencap + " "
                + "ivstatus:" + this.ivstatus + " "
                + "iverror:" + this.iverror + " "
                + "ivmode:" + this.ivmode + " "
                + "fr:" + this.fr + " "
                + "dcu2:" + this.dcu2 + " "
                + "dci2:" + this.dci2 + " "
                + "ivrun:" + this.ivrun + " "
                + "monthgencap:" + this.monthgencap + " "
                + "lastmonthgencap:" + this.lastmonthgencap + " "
                + "daygencap:" + this.daygencap + " "
                + "lastdaygencap:" + this.lastdaygencap + " "
                + "dcu3:" + this.dcu3 + " "
                + "dci3:" + this.dci3 + " "
                + "dcu4:" + this.dcu4 + " "
                + "dci4:" + this.dci4 + " "
                + "powerlimitpercent:" + this.powerlimitpercent + " "
                + "activepower:" + this.activepower + " "
                + "reactivepower:" + this.reactivepower + " "
                + "apparentpower:" + this.apparentpower + " "
                + "powerfactor:" + this.powerfactor + " "
                + "acua:" + this.acua + " "
                + "acia:" + this.acia + " "
                + "acub:" + this.acub + " "
                + "acib:" + this.acib + " "
                + "ivtype:" + this.ivtype + " "
                + "boardtemp1:" + this.boardtemp1 + " "
                + "boardtemp2:" + this.boardtemp2 + " "
                + "currentleak:" + this.currentleak + " "
                + "boardsumgen:" + this.boardsumgen + " "
                + "boardsumuse:" + this.boardsumuse + " "
                + "time:" + this.time;
        return str;
    }

}
